<?php

/*	Vulpes-backend - Web-based managegent for wireless internet providers.
	Copyright (C) 2007,2008 LinFox Serviços em Informática LTDA.

	This file is part of Vulpes-backend.

	Vulpes-backend is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	Vulpes-backend is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.

 	Please note that any front-end (client application) that is distributed
	along with Vulpes-backend, such as the Vulpes frontend by LinFox,
	is subject to it's correspending licene. */

require_once 'controller.php';
require_once 'client_dao.php';

class client_ctl extends controller
{
	protected $mode = 'clients';
	protected $model = 'client';
	protected $dao = 'client_dao';

	function __construct()
	{
		parent::__construct();
	}

	function show_all()
	{
		$client_dao = new client_dao($this->db);
		$clients = $client_dao->fetch_all(get('search'));
		$result .= '<clients>';
		foreach ($clients as $client) {
			$result .= '<client>';
			$result .= '<client_id>'.$client->client_id.'</client_id>';
			$result .= '<username>'.$client->username.'</username>';
			$result .= '<name>'.$client->name.'</name>';
			$result .= '<email>'.$client->email.'</email>';
			$result .= '<active>'.$client->active.'</active>';
			$result .= '</client>';
		}
		$result .= '</clients>';

		return $result;
	}
	
	function update_password()
	{
		$client_dao = new client_dao($db);
		$client = $client_dao->fetch($this->get('client_id'));
		if (!$client_dao->update_password($client,$this->get('new_password'))) {
			$this->errors[] = $client->error;
		}
		return $this->show();
	}

}

?>